package Classes.GameViews.ViewPanels
{
	import Classes.GameDatas.GD_Player;
	import Classes.GameUtils.GD_deal;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：May 10, 2012 3:18:06 PM 
	 */ 
	public class VP_SevenDaysRewardUI extends ViewPanel
	{
		private var _sevensArr:Array;
		
		private static var _instance:VP_SevenDaysRewardUI;
		private var _interfaceUI:Sprite;
		private var _isLq:Boolean=false;
		
		public static function get instance():VP_SevenDaysRewardUI
		{
			if(!_instance)_instance=new VP_SevenDaysRewardUI();
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
		
		public function VP_SevenDaysRewardUI()
		{
			this.init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("SevenDaysRewardUI") as Class);
			this.addChild(this._interfaceUI);
			this.addListener();
		}
		
		private function addListener():void
		{
			this.addEventListener("customCallBack",customHandler);
			this.addEventListener("close",closeWin);
		}
		
		private function customHandler(e:Event):void
		{
			//领取
			M_Communication.instance.send(127012);
		}
		
		private function closeWin(e:Event):void
		{
			this.close();
		}
		
		/**
		 * 打开七日礼包页面
		 */	
		public function open():void
		{
//			var arr:Array=this.getRewardArr();
			if(null==this.sevensArr || this.sevensArr.length<1)return;
			this._interfaceUI["setRewardData"](sevensArr,this.isLq);
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		public function getRewardArr(value:Array):Array
		{
			var endArr:Array=new Array();
			for(var i:int=0;i<value.length;i++)
			{
				var temStr:String=String((value[i] as Object).values);
				var tmpArr:Array=temStr.split("-");
				var obj:Object=new Object();
				obj.statue=tmpArr[1];
				obj.day=tmpArr[0];
				
				var sectmpArr:Array=new Array();
				for(var j:int=2;j<tmpArr.length;j++)
				{
					var items:Array=tmpArr[j].toString().split(",");
					var ss:Object=new Object();
					var icon:DisplayObject=this.getSpectialIcon(items[0],items[1]);
					ss.icon=icon;
					ss.itemNum=items[1];
					sectmpArr.push(ss);
				}
				obj.items=sectmpArr;
				endArr.push(obj);
			}
			return endArr;
		}
		
		private function getSpectialIcon(id:Number=0,num:int=0):DisplayObject
		{
			var countPic:ViewIcon=null
			switch(id)
			{
				case 1://金币
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB",creatNum:num});
					countPic.displayViewIconName=Language.jb;
					break;
				case 3:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Act",creatNum:num});
					countPic.displayViewIconName=Language.act;
					break;
				case 4:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Exp",creatNum:num});
					countPic.displayViewIconName=Language.exp;
					break;
				case 10:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_OB",creatNum:num});
					countPic.displayViewIconName=Language.ob;
					break;
				default :
					var iuserItem:IUseItem=GD_deal.instance.getDataById(id);
					var vi:ViewIcon=(iuserItem.itemPic) as ViewIcon;
					countPic=ViewIcon.creat({sourceName:vi.sourceName,picName:vi.picName,creatNum:num});
					countPic.displayViewIconName=iuserItem.itemName+"："+iuserItem.description;
					break;
			}
			countPic.setNumSpVisiable(false);
			countPic.iHeight=35;
			countPic.iWidth=35;
			return countPic;
		}

		/**
		 * 七日礼包数据源 
		 */
		public function get sevensArr():Array
		{
			return _sevensArr;
		}

		/**
		 * @private
		 */
		public function set sevensArr(value:Array):void
		{
			var tmparr:Array=getRewardArr(value);
			_sevensArr = tmparr;
		}

		/**
		 * 是否已经领取 
		 */
		public function get isLq():Boolean
		{
			return _isLq;
		}

		/**
		 * @private
		 */
		public function set isLq(value:Boolean):void
		{
			_isLq = value;
		}

		
	}
}
